package com.example.mvp.view;

import android.graphics.drawable.BitmapDrawable;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

/**
 * @author chaohaipeng  on 2018/8/14.
 */

public class PopupWindowUtil  {
    private static PopupWindowUtil instance;

    public static PopupWindowUtil getInstance() {
        if (instance==null){
            return  new PopupWindowUtil();
        }
        return instance;
    }
    private PopupWindow popupWindow;
    /**
     * 初始化
     */
  public PopupWindow initView(View contentView, int width, int height){
      popupWindow = new PopupWindow(contentView, width, height);
      // 使其聚集
      popupWindow.setFocusable(true);
      popupWindow.setClippingEnabled(false);
      // 设置允许在外点击消失
      popupWindow.setOutsideTouchable(false);
      popupWindow.setBackgroundDrawable(new BitmapDrawable());
      return popupWindow;
  }
    public boolean showingPopuWindow(){
        if (popupWindow!=null){
            return popupWindow.isShowing();
        }else{
            return false;
        }
    }

    public void showPopuWindow(View view){
      if (popupWindow!=null){
          popupWindow.showAsDropDown(view,0,0);
      }
    }
    public void dimissPopuWindow(){
        if (popupWindow!=null){
            popupWindow.dismiss();
        }

    }
}
